package glemipsc.implementations.glemips32;

import glemipsc.GLEMipsEmu;
import glemipsc.implementations.Argument;
import glemipsc.implementations.Instruction;

public class Xor extends Instruction {
	
	public Xor(Argument arg1, Argument arg2, Argument arg3) {
		arguments.add(arg1);
		arguments.add(arg2);
		arguments.add(arg3);
	}
	
	@Override
	public String getOpCode() {
		String opcode;
		
		if (arguments.get(2) instanceof Register) {
			// Register + Register
			opcode = Instruction.ALU;
			opcode += arguments.get(1).getOpCode();
			opcode += arguments.get(2).getOpCode();
			opcode += arguments.get(0).getOpCode();
			opcode += "00000";
			opcode += Instruction.ALU_XOR;
		}
		else {
			opcode = Instruction.XOR;
			opcode += arguments.get(1).getOpCode();
			opcode += arguments.get(0).getOpCode();
			opcode += arguments.get(2).getOpCode();
		}
		return opcode + "\n";
	}

	@Override
	public String getName() {
		return "XOR";
	}

	@Override
	public void emulate(GLEMipsEmu emu) {
		Register dest = (Register) arguments.get(0);
		Register op1 = (Register) arguments.get(1);
		Register op2 = (Register) arguments.get(2);
		dest.setEmulValue(op1.getEmulValue() ^ op2.getEmulValue());
	}

}
